package eleanor.ltd.isne.pages;

import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.ioc.annotations.Inject;

import eleanor.ltd.isne.annotations.BuyerAccess;
import eleanor.ltd.isne.security.AuthenticationException;
import eleanor.ltd.isne.services.Authenticator;

@BuyerAccess
public class Login {

	@Property
    private String username;

    @Property
    private String password;

    @Inject
    private Authenticator authenticator;

    @Component
    private Form loginForm;
    

//    @Inject
//    private Messages messages;

    @Log
    public Object onSubmitFromLoginForm() {
            try {
            	authenticator.login(username, password);
            } catch (AuthenticationException ex) {
//                    loginForm.recordError(Messa);
                    return null;
            }

            return Index.class;
    }

}
